//
//  WoDeViewController.swift
//  新闻
//
//  Created by 芮京 on 2018/12/10.
//  Copyright © 2018 芮京. All rights reserved.
//

import UIKit

class WoDeViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
    
    var tab:UITableView?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //标题
        self.navigationItem.title="我的"
        tabb()
    }
    
    func tabb() {
        //表格
        tab=UITableView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height), style: .grouped)
        tab?.delegate=self
        tab?.dataSource=self
        tab?.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        self.view.addSubview(tab!)
        
        //头视图
        let headerView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 150))
        headerView.backgroundColor = UIColor.lightGray
        let titleLabel = UILabel(frame: CGRect(x: 160, y: 60, width: 100, height: 40))
        titleLabel.text = "未登录"
        titleLabel.textColor = UIColor.black
        titleLabel.sizeToFit()
        headerView.addSubview(titleLabel)
        
        let img = UIImageView(frame: CGRect(x: 20, y: 20, width: 100, height: 100))
        img.image=UIImage(named: "未登录时_头像")
        headerView.addSubview(img)
        headerView.addSubview(img)
        //添加到头视图
        tab?.tableHeaderView = headerView
    }
    //分区
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    //分行
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section==0 {
            return 9
        }else{
            return 2
        }
    }
    //行内容
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")!
        cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
        //分区一
        if indexPath.section==0 {
            //数组
            var zarr = ["我的消息","我的已购","金币商城","京东特供","扫一扫","阅读公益","知识冲顶","跟帖挑战","我的钱包"]
            var farr = ["","购买的课程/直播","嘿!你的500金币,在这里","新人领取188g红包","","为乡村儿童实现梦想","品脑力,赢手机","逢楼层5必中奖",""]
            cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator//添加箭头
            //主标题
            cell.textLabel?.text=zarr[indexPath.row]
            //副标题
            cell.detailTextLabel?.text=farr[indexPath.row]
            //副标题颜色
            cell.detailTextLabel?.textColor=UIColor.lightGray
        }else{
            tableView.rowHeight = 50
            if indexPath.row==0{
                cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator//添加箭头
                tableView.rowHeight = 50
                cell.textLabel?.text="免流量看新闻"
            }else {
                cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator//添加箭头
                cell.textLabel?.text="我的已购"
            }
        }
        
        return cell
    }
    //跳转
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let j = JViewController()
        self.navigationController?.pushViewController(j, animated: true)
    }
    //返回分区头部高度
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 150
    }
    
    
}
